package com.cndw.kungfu.model.goods.app;

import java.util.Map;

import com.cndw.kungfu.domain.Union;
import com.cndw.kungfu.domain.UnionMember;
import com.cndw.kungfu.exception.ErrPopException;
import com.cndw.kungfu.ext.LanguageLib;
import com.cndw.kungfu.model.Context;
import com.cndw.kungfu.vo.PlayerReceiveVO;

/**
 * 打开获得各种资源
 * 
 * @author fantadust [9677889@qq.com]
 * @date 2011-9-13 下午3:00:05
 */
public class AppDo107 extends AppBase {

	@Override
	public boolean check() throws Exception {

		if (goodsMode.getValueA() == 4 && player.getUnionId() == 0) {
			throw new ErrPopException(LanguageLib.get("goods.use.unionerr"));
		}
		return true;
	}

	@Override
	public Map<String, Object> run() throws Exception {

		int valueA = goodsMode.getValueA();
		int valueB = goodsMode.getValueB();
		PlayerReceiveVO receive = new PlayerReceiveVO();

		switch (valueA) {
		case 1:// 给银两
			player.alterAsset(valueB);
			receive.put(PlayerReceiveVO.RECEIVE_ASSET, valueB);
			break;
		case 2:// 给经验
			player.alterExp(valueB);
			receive.put(PlayerReceiveVO.RECEIVE_EXP, valueB);
			break;
		case 3:// 给徒弟经验池
//			if (player.getVipLevel() > 0) {
//				valueB = NumberProcesser.percentClac(valueB, player.getVip().getDiscipleExpR());
//			}

			player.alterExpPool(valueB);
			receive.put(PlayerReceiveVO.RECEIVE_EXPPOOL, valueB);
			msg.put("expPool", player.getExpPool());
			break;
		case 4: // 给我的帮派贡献度
			Union union = Context.getUnionServer().getUnionByPlayerId(playerId);
			synchronized (union) {
				UnionMember member = union.getMember(playerId);
				member.setResource(member.getResource() + valueB);
				member.setHissource(member.getHissource() + valueB);
				Context.getUnionServer().updateMemberResource(member);
			}
			break;
		default:
			break;
		}
		if (!receive.isEmpty()) {
			msg.put("receive", receive);
		}
		return msg;
	}
}
